﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;

namespace K9Nano.Dependency
{
    public class DefaultIocHelper: IIocHelper
    {
        private readonly IServiceCollection _services;

        public DefaultIocHelper(IServiceCollection services)
        {
            _services = services;
        }

        public bool IsRegister(Type type)
        {
            return _services.Any(x => x.ServiceType == type);
        }

        public IEnumerable<Type> GetRegisteredTypes(Func<Type, bool> filter)
        {
            return _services.Where(x => filter(x.ServiceType))
                .Select(x => x.ServiceType);
        }
    }
}